//Grozi Ties
// David Ing and Jae Shin Woo
//
// Grozi.SendA.ck
// This is a program that sends OSC packets to port 7000.  It is
// meant to simulate the data sent to us by the User Interface
// team
//
// This program is based off of the code from the TIES team of
// Fall 2010
//----------------------------------------------------------------

"localhost" => string hostname; 
7000 => int port;  // port that it sends to

if( me.args() ) me.arg(0) => hostname;
if( me.args() > 1 ) me.arg(1) => Std.atoi => port;
OscSend xmit;

// sets the hose name at the given port
xmit.setHost( hostname, port );
Hid hi; 
0 => int cont;
0 => int a;
HidMsg msg;
0 => int device; 

if( me.args() ) me.arg(0) => Std.atoi => device;
if( !hi.openMouse( device ) ) me.exit();
0 => int Xpos;

while( true ){
    hi => now;
    while( hi.recv( msg ) ){
        Xpos + msg.deltaX => Xpos;
        if( msg.isButtonDown() ){
            if( msg.deltaX ){ 
                <<< "SENDING: ", Xpos  >>>;
                xmit.startMsg( "/edge", "i" );
                cont + 1 => cont;
                if(cont==1){
                    0 => cont;
                    <<<"SSS">>>; 
                    (Xpos/10) =>xmit.addInt; 
                } 
            }
        }
    }
}

